package com.sht.product.yuea.weixin.request;

import java.util.HashMap;
import java.util.Map;

import com.sht.common.components.config.Config;
import com.sht.common.components.json.JSONUtil;
import com.sht.product.yuea.common.Constants;

public class PageAuthGetTockenByCodeRequest{
	private Map<String, String> urlPara=new HashMap<String, String>();
	public static String appid =Config.getStringNotEmpty(Constants.WEI_XIN_APPID);
	public static String secret =Config.getStringNotEmpty(Constants.WEI_XIN_SECRET);
	private static String URL=Config.getStringNotEmpty(Constants.WEI_XIN_BASE_URL)+Config.getStringNotEmpty(Constants.WEI_XIN_OAUTH2_ACCESS_TOKEN_URL);

	
	public PageAuthGetTockenByCodeRequest(String code,String grant_type) {
		
		urlPara.put("appid", appid);
		urlPara.put("secret", secret);
		urlPara.put("code", code);
		urlPara.put("grant_type", grant_type);
	}

	
	public String getAccessToken() {
		SimpleGet simpleGet=new SimpleGet(URL+BaseRequest.generateUrlPara(urlPara));
		return JSONUtil.get(simpleGet.get(), "access_token");
	}
	public String getUserOpenId() {
		SimpleGet simpleGet=new SimpleGet(URL+BaseRequest.generateUrlPara(urlPara));
		return JSONUtil.get(simpleGet.get(), "openid");
	}
}
